<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Object</title>
  </head>
  <body>
    <p>Object.is（）判断两个值是否相等</p>
    <pre>
         Object.is(value1:any,value2:any):boolean
      </pre
    >
    <p>
      Object.assign()将源对象source可枚举的自身（非继承）属性复制到目标对象target中
    </p>
    <pre>
       Object.assign(target:any,source:any);
       let target={a:1}
       let source1 = {b:2,c:3}
       let source2 = {b:12,d:5} //相同属性，后面的会覆盖前面的
       Object.assign(target,source1,source2);   // target:{a: 1, b: 12, c: 3, d: 5}
</pre
    >
    <p>如果target不是对象，也无法转化为对象，则报错</p>
    <pre>
      Object.assign(null); //报错 Cannot convert undefined or null to object
      Object.assign(undefined)；  //报错 Cannot convert undefined or null to object
    </pre>
    <p>
      Object.assign()复制的方法是浅复制：如果源对象的属性是对象，则复制后新的对象得到的是这给属性的引用
    </p>
    <pre>
      let obj1={a:{b:1}}
      let obj2=Object.assign({},obj1)

      obj1.a.b=2; //修改source的属性值
      console.log(obj2.a.b); // 2  obj2的属性值也被修改了
    </pre>
  </body>
</html>
<script>
  // Object.is();
  let target = { a: 1 };
  let source1 = { b: 2, c: 3 };
  let source2 = { b: 12, d: 5 }; //相同属性，后面的会覆盖前面的
  Object.assign(target, source1, source2); // target:{a: 1, b: 12, c: 3, d: 5}
  //Object.assign(null); //报错  Cannot convert undefined or null to object
  //Object.assign(undefined); //报错  Cannot convert undefined or null to object
  let obj1 = { a: { b: 1 } };
  let obj2 = Object.assign({}, obj1);

  obj1.a.b = 2; //修改source的属性值
  console.log(obj2.a.b); // 2  obj2的属性值也被修改了
</script>
